<?php session_start ();
require_once '../lib/sql.php';
$sql=new Sql();
$card;
if (isset ( $_SESSION ['card'] )) {
	$card = $_SESSION ['card'];
} else {
	$card=array();
}
if(isset($_REQUEST['id'])){
	$id=$_REQUEST['id'];
	while (current($card)){
		$key=key($card);
		$sp=$card[$key];
		if($sp['id']==$id){
			$sp['count']=$sp['count']+1;
			$card[$key]=$sp;
			$_SESSION['card']=$card;
			goto out;
		}
		next($card);
	}
	
	
	$rs = @mysql_query("select s.idsp,s.`name`,s.price,s.image from sanpham as s where idsp = $id and hide=1");
	if(@mysql_num_rows($rs)==1){
		$row=@mysql_fetch_array($rs);
		$sp=array(	"id"=>$row['idsp'],
					"name"=>$row['name'],
					"price"=>$row['price'],
					"count"=>1,
					"image"=>$row['image']);
		$card[count($card)]=$sp;
		$_SESSION['card']=$card;
	}
	unset($sql);
	@mysql_free_result($rs);
}

out:echo count($card);

?>